Skip to content

Add pthread mutex deadlock detection for debug builds #24607

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 9, 2025

Conversation

sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Jun 18, 2025

This would really have helped in at least detecting the deadlock that was found in #24570 / #24565

@sbc100 sbc100 force-pushed the deadlock_detection branch from a57b588 to 0e10a5e Compare June 18, 2025 23:59
@sbc100 sbc100 requested review from brendandahl, kripken and juj June 18, 2025 23:59
@sbc100 sbc100 force-pushed the deadlock_detection branch from 0e10a5e to efb88c5 Compare June 19, 2025 00:02
@sbc100 sbc100 force-pushed the deadlock_detection branch from efb88c5 to a8d3d3f Compare June 19, 2025 14:20
@sbc100 sbc100 requested review from RReverser and kripken July 7, 2025 17:10
Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nits optional)

@sbc100 sbc100 force-pushed the deadlock_detection branch from a8d3d3f to e59d085 Compare July 7, 2025 21:45
@brendandahl
Copy link
Collaborator

I tried out this change and it does cause an assert in test_pthread_cancel.c, though that test is only run in -O3 currently.

@sbc100 sbc100 force-pushed the deadlock_detection branch 2 times, most recently from c06ae77 to cf6ce4a Compare July 8, 2025 21:07
@sbc100 sbc100 enabled auto-merge (squash) July 8, 2025 21:34
@sbc100 sbc100 force-pushed the deadlock_detection branch 3 times, most recently from 2b24c68 to 264052a Compare July 8, 2025 23:02
This would really have helped in at least detecting the deadlock that
was found in emscripten-core#24570 / emscripten-core#24565
@sbc100 sbc100 force-pushed the deadlock_detection branch from 264052a to 42fb00c Compare July 8, 2025 23:40
// We can get here for normal mutexes too, but only in debug builds
// (where we track ownership purely for debug purposed).
if ((type & 15) == PTHREAD_MUTEX_NORMAL) return 0;
#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can we get here? Is it because of one of the changes in this PR?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, prior to this change normal mutex's never make it here since they don't need to track ownership.

Co-authored-by: Alon Zakai <alonzakai@gmail.com>
@sbc100 sbc100 disabled auto-merge July 9, 2025 18:17
@sbc100 sbc100 merged commit 4780cc2 into emscripten-core:main Jul 9, 2025
2 of 14 checks passed
@sbc100 sbc100 deleted the deadlock_detection branch July 9, 2025 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants